package br.com.puertorico.mecanismos.ui.resolver;

import java.net.URL;

import br.com.puertorico.common.loggin.Logger;

import com.sun.faces.facelets.impl.DefaultResourceResolver;

/**
 * Esta classe faz a resolu&ccedil;&atilde;o dos recursos do facelets, ou seja,
 * ela recupera as p&aacute;ginas xhtml que representam os componentes gui do
 * classloader, ou inv&eacute;s de onde o facelets est&aacute; acostumado
 * (webcontent\pastas).
 *
 * @author Daniel Camargo
 * @version 1.0
 */
public class FaceletsResourceResolver extends DefaultResourceResolver {

	private static Logger _log = Logger
			.getLogger(FaceletsResourceResolver.class);

	/**
	 * @see com.sun.facelets.impl.DefaultResourceResolver#resolveUrl(java.lang.String)
	 */
	@Override
	public URL resolveUrl(String resource) {
		_log.info("ResolverUrl invocado com o valor #0", resource);
		URL resourceUrl = super.resolveUrl(resource);
		if (resourceUrl == null) {
			if (resource.startsWith("/")) {
				resource = resource.substring(1);
			}
			resourceUrl = Thread.currentThread().getContextClassLoader()
					.getResource(resource);
		}
		_log.info("Resolvido com valor #0", resourceUrl);
		return resourceUrl;
	}
}
